﻿/**
 * Created by Administrator
 */
// var apiUrl = "http://47.96.115.146/njwebsite/website/home";
// var apiUrl2 = "http://47.96.115.146/njwebsite/website/Excel";
var apiUrl = "http://bxh0736.vicp.cc:28499/njwebsite/home";
var apiUrl2 = "http://bxh0736.vicp.cc:28499/njwebsite/Excel";
var user={
    account:'FSH20180514',
    key:'kingdee',
    // typecode:'hc'
};
var pageInfo = {
    pagecount:10
}

var ARegexp = {
    mobile:/^((13[0-9])|(14[5,7,9])|(15[^4])|(18[0-9])|(17[0,1,3,5,6,7,8]))\d{8}$/,
    email:/^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/
};

function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
};

function setCookie(cookiename, cookievalue, hours) {
    var date = new Date();
    date.setTime(date.getTime() + Number(hours) * 3600 * 1000);
    document.cookie = cookiename + "=" + cookievalue + "; path=/;expires = " + date.toGMTString();

}

function getCookie(n){
    var name = n + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i<ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
    }
    return "";
}

function removeCookie(name){
    setCookie(name, 1, -1);
}


Vue.component('asn-header', {
    data: function () {
        return {
            username:decodeURIComponent(getCookie('username'))
        }
    },
    template: '<div class="header">\n' +
    '            <div class="base-width cf">\n' +
    '                <a href="./main.html" class="fl">\n' +
    '                    <img class="logo" src="../source/img/logo.png" alt="" />\n' +
    '                </a>\n' +
    '                <el-dropdown class="username fr" v-if="username" v-cloak @command="handleCommand">\n' +
    '                      <span class="el-dropdown-link">\n' +
    '                        {{username}}<i class="el-icon-arrow-down el-icon--right"></i>\n' +
    '                      </span>\n' +
    '                    <el-dropdown-menu class="username-dropdown" slot="dropdown">\n' +
    '                        <el-dropdown-item command="1">\n' +
    '                            退出\n' +
    '                        </el-dropdown-item>\n' +
    '                    </el-dropdown-menu>\n' +
    '                </el-dropdown>\n' +
    '            </div>\n' +
    '        </div>',
    methods:{
        isLogin:function(){
            var username = getCookie('username');
            var type = getCookie('type');
            if(username && username != 'undefined' && type &&  type != 'undefined'){
                return true;
            }
            return false;
        },
        loginout:function(){
            removeCookie('username');
            removeCookie('type');
            location.href='./login.html';
        },
        handleCommand:function(command){
            if(command == 1){
                this.loginout()
            }
        }
    },
    created:function(){
        if(!this.isLogin()){ //登录
            location.href = './login.html';
        }
    }
})
